package com.kky.pp.popup

import android.app.Activity
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.kky.pp.common.Constant
import com.kky.pp.R
import com.kky.pp.entity.CardInfoEntity
import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.OkHttpManager
import com.custom.base.http.SDOkHttpResoutCallBack
import com.custom.base.util.ToastUtil
import io.rong.imkit.utils.AnimatorUtils
import razerdp.basepopup.BasePopupWindow

class UserClickMorePopup(var ctx: Activity, var bundle: Bundle, var listener: UserActionListener) :  BasePopupWindow(ctx) {
    init {
        setContentView(R.layout.popup_user_click_more)
        initView()
        showAnimation = AnimatorUtils.popupWindowShow()
        dismissAnimation= AnimatorUtils.popupWindowDismiss()
    }

    private fun initView() {
        val outsideContainer = findViewById<View>(R.id.vPopupReportBlockOutsideContainer)
        val dialogCancel = findViewById<TextView>(R.id.txtPopupReportBlockCancel)

        outsideContainer.setOnClickListener {
            dismiss()
        }
        dialogCancel.setOnClickListener {
            dismiss()
        }
        val dialogReport = findViewById<TextView>(R.id.txtPopupReportBlockReport)
        val dialogBlock = findViewById<TextView>(R.id.txtPopupReportBlockBlock)
        dialogReport.setOnClickListener {
            dismiss()
            listener.userReport()
        }
        dialogBlock.setOnClickListener {
            OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {
                    requestBody.setPost(Constant.user_add_action_url)
                    requestBody.add("opType", 1)
                    requestBody.add("userCodeFriend", bundle.getString("userCodeFriend",""))
                }
            }, object : SDOkHttpResoutCallBack<CardInfoEntity>() {
                override fun onSuccess(entity: CardInfoEntity) {
                    ToastUtil.toast(ctx.getString(R.string.black_toast))
                    dismiss()
                    listener.userBlack()
                }


                override fun onFailure(code: Int, msg: String) {
                }
            }, isShowDialog = false)
        }
        setOutSideDismiss(true)
        isOutSideTouchable = true
    }

    interface UserActionListener{
        fun userReport()
        fun userBlack()
    }
}